﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Web.Script.Serialization;

namespace MvcControlsToolkit
{
    public class Plot: Control
    {
        public string CssClass { get; set; }

        public List<PlotSeries> Series { get; set; }

        public Plot AddSeries(PlotSeries series)
        {
            Series.Add(series);

            return this;
        }

        public Plot(string name) : base(name)
        {
            Series = new List<PlotSeries>();
        }

        protected override string GetJScript()
        {
            var result = new StringBuilder();

            var jsserializer = new JavaScriptSerializer();

            jsserializer.Serialize(Series.Select(x => x.Data), result);

            result.Append(");");

            result.Insert(0, "$.jqplot(\"" + Name + "\", ");

            return result.ToString();
        }

        protected override string GetHtml()
        {
            var html = new StringBuilder();

            html.Append(String.Format("<div id=\"{0}\" class=\"{1}\"></div>", Name, CssClass));

            return html.ToString();
        }
    }

    public class PlotSeries
    {
        public string Name { get; set; }
        public string Type { get; set; }
        public Color Color { get; set; }
        public object Data { get; set; }
    }

    public class PlotLegend
    {
        public string Layout { get; set; }
        public string Align { get; set; }
        public string VerticalAlign { get; set; }
        public int X { get; set; }
        public int Y { get; set; }
        public bool Floating { get; set; }
        public int BordingWidth { get; set; }
        public string Backgroung { get; set; }
    }

    public class PlotTitle
    {
        public string Text { get; set; }
        public int X { get; set; }
        public int Y { get; set; }
    }
}
